//
//  FooterHomeScreenView.m
//  ZooNgonDoiOS
//
//  Created by Trung sound on 7/9/12.
//  Copyright (c) 2012 Personal. All rights reserved.
//

#import "FooterHomeScreenView.h"
#import "RestKit/JSONKit.h"

#define DONT_FIND_PLACE @"---------------------"

@implementation FooterHomeScreenView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        _lbLocation = [[UILabel alloc]init];
        _btnPickLocation = [[UIButton alloc]init];
        
        [self setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:IMG_VIEW_FOOTER]]];
        _lbLocation.frame = CGRectMake(5, 5, 260, 20);
        [_lbLocation setText:DONT_FIND_PLACE];
        _lbLocation.backgroundColor = [UIColor clearColor];
        [_lbLocation setFont:[UIFont systemFontOfSize:15]];
        
        [_lbLocation setTextColor:[UIColor whiteColor]];
        _btnPickLocation.frame = CGRectMake(320 - 34, 1, 24, 24);
        [_btnPickLocation setBackgroundImage:[UIImage imageNamed:IMG_BTN_PICKLOCATION] forState:UIControlStateNormal];
        [_btnPickLocation setShowsTouchWhenHighlighted:YES];
        [self addSubview:_lbLocation];
        [self addSubview:_btnPickLocation];
    }
    return self;
}

-(void)setLocationLatitude:(CGFloat)latitude longitude:(CGFloat)longitude {
    cLatitude = latitude;
    cLongtitude = longitude;
    [self reverseGeocode];
    
}

- (void)reverseGeocode {
    [SVGeocoder reverseGeocode:CLLocationCoordinate2DMake(cLatitude, cLongtitude)
                    completion:^(NSArray *placemarks, NSError *error) {
                        UIAlertView *alertView;
                        
                        if(!error && placemarks) {
                            SVPlacemark *placemark = [placemarks objectAtIndex:0];
//                            alertView = [[UIAlertView alloc] initWithTitle:@"Placemark Found!" message:[placemark description] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];

                            [_lbLocation setText:[placemark description]];
                            
                        } else {
                            alertView = [[UIAlertView alloc] initWithTitle:@"Không xác định được vị trí" message:@"Kiểm tra lại Local Service" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
                            [_lbLocation setText:DONT_FIND_PLACE];
                            [alertView show];
                            [alertView release];
                        }
                        
//                        [alertView show];
//                        [alertView release];
                    }];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
